﻿Public Class clsAlertManager

    Declare Function PlaySound Lib "coredll.dll" (ByVal pszSound As String, ByVal hMod As IntPtr, ByVal sf As SoundEnum) As Boolean

    Private _Speed As Double
    Public Property Speed() As Double
        Get
            Return _Speed
        End Get
        Set(ByVal value As Double)
            If value >= Glob.MobileSettings.SpeedAlert And _Speed < Glob.MobileSettings.SpeedAlert Then
                Me.PlaySound("1.wav")
            End If
            _Speed = value
        End Set
    End Property

    ''' <summary>
    ''' Play alert sound if the speed exceed the speed limit
    ''' </summary>
    ''' <param name="SoundFile">Alert Sound File</param>
    ''' <remarks>Sound file should be wave, the function will get the language settings automatically
    ''' in order to play the correct sound language
    ''' </remarks>
    Private Sub PlaySound(ByVal SoundFile)
        Try
            Dim FileToPlay As String = SoundFile
            FileToPlay = System.IO.Path.Combine(Glob.MobileSettings.AppPath, "Sounds")
            FileToPlay = System.IO.Path.Combine(FileToPlay, Glob.MobileSettings.SoundLanguage)
            FileToPlay = System.IO.Path.Combine(FileToPlay, Glob.MobileSettings.SoundLanguage.Substring(0, 1) & SoundFile)
            PlaySound(FileToPlay, IntPtr.Zero, SoundEnum.SND_ASYNC)
        Catch ex As Exception
            PushLog("Error in clsAlertManager.PlaySound: " & ex.Message)
        End Try
    End Sub

End Class
